package com.ruoyi.management.dao.mapper;

import com.ruoyi.management.pojo.dto.DbInfoDto;
import com.ruoyi.management.pojo.entity.KhbhDbbh;
import com.ruoyi.management.pojo.po.AmmeterResultPo;
import com.ruoyi.management.pojo.po.CheckPO;
import com.ruoyi.management.pojo.po.MouthReadPO;
import com.ruoyi.management.pojo.vo.AmmeterTimeVO;
import com.ruoyi.management.pojo.vo.CheckVO;
import com.ruoyi.management.pojo.vo.EneryVO;
import lombok.Data;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Mapper
public interface EnergyMapper {
    //实时数据
    List<AmmeterTimeVO> readData(@Param("dbbh") String dbbh,@Param("qymc") String qymc);
    //每日电量
    List<EneryVO> dayEnergy(@Param("dbbh") String dbbh, @Param("qymc") String qymc, @Param("date") Date date, @Param("zt") String zt);
    //没小时用电量


    List<EneryVO> selectmouth(
            @Param("dbbh") String dbbh,
            @Param("qymc") String qymc,
            @Param("month") @DateTimeFormat(pattern = "yyyy-MM") Date month
    );
    //月电量分日
    @MapKey("date")
    List<Map<String, Object>> monthDayEnery(@Param("dbbh") String dbbh,@Param("month") Date month);

    //通过日期查询符合的电表
    List<EneryVO> selectQldb(@Param("dbbh") String dbbh, @Param("qymc") String qymc, @Param("zt") String zt);

    // 获取 dbdata 最新 total_power
    @Select("SELECT * FROM dbday WHERE dbbh = #{dbbh} ORDER BY timestamp DESC LIMIT 1")
    Map<String, Object> getLastDbDataByDbbh(String dbbh);


    // 获取 dbmouth 当前月份的 mouthRead
    @Select({
            "<script>",
            "SELECT mouthRead FROM dbmouth",
            "WHERE dbbh = #{dbbh}",
            "ORDER BY timestamp DESC LIMIT 1",
            "</script>"
    })
    BigDecimal getMouthReadByDbbhAndMonth(@Param("dbbh") String dbbh, @Param("month") Date month);

    //查询符合年份的电表
    List<KhbhDbbh> selectQldb11(@Param("dbbh") String dbbh,@Param("qymc") String qymc,@Param("year") Date year);
    //查询核查联电量列表
    List<CheckVO> checkEnergyList(@Param("date") Integer date, @Param("zt") String zt,@Param("tgszt") String[] values);

    List<KhbhDbbh> selectQldbzymx1(@Param( "month") LocalDate month, @Param( "zt") String zt);
    //新增核查联电量
    Boolean checkEnergy(CheckPO checkPO);

    BigDecimal selectdbzyc(@Param("date") Date date,@Param("zt") String zt);

    List<EneryVO> selectlastmouth(@Param("dbbh") String dbbh,@Param("qymc") String qymc,@Param("month") Date month, @Param("zt") String zt);

    @MapKey("month")
    List<Map<String, Object>> yearMonthEnery(@Param("dbbh") String dbbh,@Param("date") Integer date);
    //存入数据
    Boolean insertData(AmmeterResultPo po);
    //通过电表编号查询信息
    AmmeterTimeVO selectAmmeterTimeVO(String dbbh);
    //查询最近结算日电量
    BigDecimal selectMouthUsed(String dbbh);

    //存入项目月度电费统计表qldbydyz
    Boolean checkdf(CheckPO checkPO);


    /**
     * 查询选择的年的电量
     *
     * @param dbInfoDto 电表信息
     * @return 当年的电量
     */
    List<MouthReadPO> selectYearEnergy(DbInfoDto dbInfoDto);


    /**
     * 查询选择的年上一年的电量
     *
     * @param dbInfoDto 电表信息
     * @return 当年的电量
     */
    List<MouthReadPO> selectLastYearEnergy(DbInfoDto dbInfoDto);


    /**
     * 查询电表编号、企业名称、房间号
     *
     * @param dbInfoDto 电表信息
     * @return 电表编号列表
     */
    List<EneryVO> selectDbBh(DbInfoDto dbInfoDto);

}
